#pragma once

#include <map>
#include "userAI.h"
#include "userAPI.h"
#include "ArmyState.h"

using namespace std;
using namespace AI9;

class BasicAI : public UserAI
{
public:
	BasicAI(GameInfo* game, int user_id) : UserAI(game, user_id) { global_instance = this; }
	vector<GeneralType> pickGeneral(int numGeneral, GeneralType yourType, vector<Pair> &pos, vector<SoldierType> &soldierType, vector<int> &numSoldier);
	vector<ActionBase*> getAction(GameInfo* game);

	static BasicAI *instance() { return global_instance; }
	static BasicAI *global_instance;

	void append_actions(vector<ActionBase*> &actions)
	{
		for (vector<ActionBase*>::iterator it = actions.begin(); it != actions.end(); ++it)
			action_queue.push_back(*it);
	}

	vector<ActionBase*> &get_action_queue() { return action_queue; }

	ArmyStateNS::BaseState *get_army_state(GeneralType name)
	{
		return army_state_map[name];
	}

	void set_army_state(GeneralType name, ArmyStateNS::BaseState *state)
	{
		LOG << name << " enters " << state->get_type() << endl;
		army_state_map[name] = state;	//	TODO	memeory leak
	}

	UserAPI &get_api() { return m_api; }

protected: 
	UserAPI m_api;
	vector<ActionBase*> action_queue;
	std::map<GeneralType, ArmyStateNS::BaseState*> army_state_map;
};
